//
//  RW_MusicItemCollectionViewCell.m
//  SleepApp
//
//  Created by MAC on 2021/3/29.
//  Copyright © 2021 RiceWang. All rights reserved.
//

#import "RW_MusicItemCollectionViewCell.h"
#import "UIColor+WLGradient.h"
#import "RW_CopyrightShowView.h"

@interface RW_MusicItemCollectionViewCell (){
    RW_MusicItemCollectionViewCellModel *_model;
}
@property (nonatomic,strong) UILabel *music_label;
@property (nonatomic,strong) UIImageView *image_view;
@property (nonatomic,strong) UIView *mask_view;
@property (nonatomic,strong) UIButton *author_button;
@end
@implementation RW_MusicItemCollectionViewCell
-(void)bind_row_data:(WLBaseCollectionViewLayerRow *)sender{
    if ([sender.data isKindOfClass:RW_MusicItemCollectionViewCellModel.class]){
        _model = sender.data;
        
        self.music_label.text = _model.music_name;
        [self.image_view wl_setImage:_model.songModel.cover];
    }
}
-(void)bind_delegate:(id)sender{
    
}
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = UIColor.whiteColor;
        self.layer.cornerRadius = 4;
        self.clipsToBounds = YES;

        [self addSubview:self.image_view];
        [self addSubview:self.mask_view];
        
        [self addSubview:self.music_label];
        
        [self addSubview:self.author_button];
        
        [self.music_label mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self).mas_offset(5);
            make.right.mas_equalTo(self).mas_offset(-5);
            make.bottom.mas_equalTo(self).mas_offset(-5);
        }];
        [self.mask_view mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.bottom.mas_equalTo(self);
            make.height.mas_equalTo(self.mas_height).multipliedBy(.5f);
        }];
        [self.image_view mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.insets(UIEdgeInsetsZero);
        }];
        [self.author_button mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self).mas_offset(5);
            make.right.mas_equalTo(self).mas_offset(-5);
        }];
    }
    return self;
}
#pragma mark -- 操作
-(void)click_author_button:(UIButton *)sender{
    RW_CopyrightShowView.init_wl()
    .maskAlpha_wl(.5f)
    .addData_wl(_model.songModel)
    .show_wl();
}
#pragma mark -- 懒加载
-(UILabel *)music_label{
    if (!_music_label){
        _music_label = [[UILabel alloc]init];
        _music_label.textColor = UIColor.whiteColor;
        _music_label.font = [UIFont systemFontOfSize:14 weight:UIFontWeightMedium];
        _music_label.numberOfLines = 2;
    }
    return _music_label;
}
-(UIImageView *)image_view{
    if (!_image_view){
        _image_view = [[UIImageView alloc]init];
        _image_view.contentMode = UIViewContentModeScaleAspectFill;
        _image_view.clipsToBounds = YES;
    }
    return _image_view;
}
-(UIView *)mask_view{
    if (!_mask_view){
        _mask_view = [[UIView alloc]init];
        _mask_view.backgroundColor = [UIColor fromColor:UIColor.clearColor toColor:UIColor.blackColor length:self.width_wl isHorizontal:NO];
    }
    return _mask_view;
}
-(UIButton *)author_button{
    if (!_author_button){
        _author_button = [[UIButton alloc]init];
        [_author_button setImage:[UIImage svgName:@"public_author_small_icon"] forState:UIControlStateNormal];
        [_author_button addTarget:self action:@selector(click_author_button:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _author_button;
}
@end

@implementation RW_MusicItemCollectionViewCellModel
-(NSString *)music_name{
    if (!_music_name){
        _music_name = self.songModel.name;
    }
    return _music_name;
}
@end
